<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true">
              <el-form-item label="用户名称" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" border :data="listData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible" :key="item.key" :label="item.label" align="center" :prop="item.key" >
                <template v-slot="scope">
                  <template v-if="item.key === '任务要求'">
                    <el-tooltip :content="scope.row[item.key]">
                      <div class="zi-hide">{{ scope.row[item.key] }}</div>
                    </el-tooltip>
                  </template>
                </template>
              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="180" align="center">
              <template v-slot="scope">
                <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)">修改</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <formVue ref="formRef"></formVue>

  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'

// 组件
import formVue from '@/views/qualityAdmin/sampling/form.vue'
const formRef = ref(null)

// 列显隐信息
const columns = ref([
  { key: '样品类型', label: `样品类型`, visible: true, children: [] },
  { key: '样品编号', label: `样品编号`, visible: true, children: [] },
  { key: '检测项目', label: `检测项目`, visible: true, children: [] },
  { key: '标准值/预期值', label: `标准值/预期值`, visible: true, children: [] },
  { key: '检测结果', label: `检测结果`, visible: true, children: [] },
  { key: '偏差/回收率', label: `偏差/回收率`, visible: true, children: [] },
  { key: '是否合格', label: `是否合格`, visible: true, children: [] },
  { key: '问题分析', label: `问题分析`, visible: true, children: [] },
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(120)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([
  {
    "样品类型": "质控样",
    "样品编号": "QC-20250709",
    "检测项目": "镉（水）",
    "标准值/预期值": "0.100mg/L",
    "检测结果": "0.095mg/L",
    "偏差/回收率": "95%",
    "是否合格": "是",
    "问题分析": "-"
  },
  {
    "样品类型": "实验室空白",
    "样品编号": "LB-20250709",
    "检测项目": "汞（土壤）",
    "标准值/预期值": "0",
    "检测结果": "未检出",
    "偏差/回收率": "-",
    "是否合格": "是",
    "问题分析": "-"
  },
  {
    "样品类型": "现场空白",
    "样品编号": "FB-20250709",
    "检测项目": "挥发性有机物",
    "标准值/预期值": "0",
    "检测结果": "0.02mg/kg",
    "偏差/回收率": "-",
    "是否合格": "否（超标）",
    "问题分析": "采样瓶密封不良"
  },
  {
    "样品类型": "平行样1",
    "样品编号": "P-20250709-1",
    "检测项目": "氨氮（废水）",
    "标准值/预期值": "-",
    "检测结果": "35.6mg/L",
    "偏差/回收率": "-",
    "是否合格": "-",
    "问题分析": "-"
  },
  {
    "样品类型": "平行样2",
    "样品编号": "P-20250709-2",
    "检测项目": "氨氮（废水）",
    "标准值/预期值": "-",
    "检测结果": "34.8mg/L",
    "偏差/回收率": "RD=2.3%",
    "是否合格": "是",
    "问题分析": "-"
  }
]);


// 获取数据
const getList = () => {
  loading.value = false
}

// 搜索
const handleQuery = () => {
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}
const handleEdit = (data) => {
  formRef.value.edit(data)
}


getList()
</script>
